package com.csdj.questions.controller;


import com.csdj.questions.common.CacheConstant;
import com.csdj.questions.common.WebResult;
import com.csdj.questions.common.WebResultMsgCode;
import com.csdj.questions.entity.AttentionQuestion;
import com.csdj.questions.mapper.AttentionQuestionMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 关注问题表（我关注的问题） 前端控制器
 * </p>
 *
 * @author 刘宇
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/attention-question")
public class AttentionQuestionController extends BaseController{
    @Resource
    private AttentionQuestionMapper attentionQuestionMapper;

    /**
     * 插入，存两个id，uid从请求头获取，另一个问题id，关注问题
     * @name 刘宇
     * @return
     */
    @PostMapping("/insertAttentionQuestion/{QuestionId}") //@PathVariable 获取地址栏参数
    public WebResult insertAttentionQuestion(@PathVariable String QuestionId,
                                             HttpServletRequest request,
                                             AttentionQuestion attentionQuestion){
        int uid = getUid(request);//获取请求头信息
        attentionQuestion.setUserId(uid);
        attentionQuestion.setQuesId(QuestionId);
        int jg = attentionQuestionMapper.insert(attentionQuestion);
        if(jg > 0){
            //返回一个0 代表成功
            return new WebResult(WebResultMsgCode.SUCCESS).putData("attentionQuestion",jg);
        }
        //返回1 代表失败
        return new WebResult(WebResultMsgCode.FAIL);
    }
}
